
const enterToNext = {
  install (Vue, options) {
    //输入框 enter键切换
    Vue.directive('enterToNext', {
      inserted: function(el) {
        let inputs = el.querySelectorAll('[key-next]')
        //绑定回写事件
        for (var i = 0; i < inputs.length; i++) {
          inputs[i].setAttribute('keyFocusIndex', i)
          inputs[i].addEventListener('keyup', (ev) => {
            if (ev.keyCode === 13) {
              var attrIndex = ev.srcElement.getAttribute('keyFocusIndex')
              var ctlI = parseInt(attrIndex)
              if (ctlI < inputs.length - 1) {
                let nextint = ctlI + 1
                for (var j = nextint; j < inputs.length; j++) {
                  let clazz = inputs[j].getAttribute('class')

                  if (clazz.indexOf('disabled') < 0) {
                    console.log( clazz.indexOf('ant-calendar-picker'))
                    if (clazz.indexOf('ant-calendar-picker')>=0)
                    {
                      inputs[j].children[0].children[0].click();
                    }else {
                      inputs[j].focus()
                      inputs[j].select()
                    }

                    break
                  }
                }
              }
            }
          })
        }
      }
    })
  }
};

export default enterToNext;